package pl.skubicha.utils;

import java.util.ArrayList;
import java.util.List;

import pl.skubicha.domain.Subjects;
import pl.skubicha.response.SubjectDTO;
import pl.skubicha.response.SubjectForGroupsDTO;

public class SubjectMapper {

	public static SubjectDTO map( final Subjects subject ) {
		final SubjectDTO dto = new SubjectDTO();
		dto.setId( subject.getId() );
		dto.setSubjectName( subject.getSubjectName() );
		dto.setUser( subject.getUsers() );
		dto.setGroups( subject.getGroups() );

		return dto;
	}

	public static Subjects map( final SubjectDTO dto ) {
		final Subjects subject = new Subjects();
		subject.setId( dto.getId() );
		subject.setSubjectName( dto.getSubjectName() );
		subject.setUsers( dto.getUser() );
		subject.setGroups( dto.getGroups() );

		return subject;
	}

	public static List< SubjectDTO > map( final Iterable< Subjects > subjects ) {
		final List< SubjectDTO > dtos = new ArrayList< SubjectDTO >();

		for ( final Subjects subject : subjects ) {
			dtos.add( map( subject ) );
		}

		return dtos;
	}

	public static SubjectForGroupsDTO mapSubjectToGroupsDTO( final Subjects subject ) {
		final SubjectForGroupsDTO dto = new SubjectForGroupsDTO();
		dto.setId( subject.getId() );
		dto.setSubjectName( subject.getSubjectName() );

		return dto;
	}

	public static Subjects map( final SubjectForGroupsDTO dto ) {
		final Subjects subject = new Subjects();
		subject.setId( dto.getId() );
		subject.setSubjectName( dto.getSubjectName() );

		return subject;
	}

	public static List< SubjectForGroupsDTO > mapSubjectsToGroupsDTO( final Iterable< Subjects > subjects ) {
		final List< SubjectForGroupsDTO > dtos = new ArrayList< SubjectForGroupsDTO >();

		for ( final Subjects subject : subjects ) {
			dtos.add( mapSubjectToGroupsDTO( subject ) );
		}

		return dtos;
	}
}
